<template>
  <div class="adminLogin">
    <div class="bg">
      <img :src="_src + 'images/admin/18-05-01-2.png'" alt="background">
    </div>
    <div class="load">
      <div class="loadBg"></div>
      <div class="inputList">
        <div>
          <span>登录</span>
        </div>
        <div class="checkBox">
          <el-input v-model="adminName" placeholder="请输入帐号" maxlength="10"></el-input>
          <span v-show="userNameError">请输入正确的账号！</span>
        </div>
        <div class="checkBox">
          <el-input type="password" v-model="adminPwd" placeholder="请输入密码" maxlength="10"></el-input>
          <span v-show="userPwdError">请输入正确的密码！</span>
        </div>
        <div>
          <el-button @click="back()">返回</el-button>
          <el-button type="primary" @click="load()">登录</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ALoginService from "./login.service";
export default {
  name: "ALogin",
  data() {
    return {
      _src: '',
      adminName: "",
      adminPwd: "",
      userNameError: false,
      userPwdError: false
    };
  },
  methods: {
    load() {
      if (this.adminName.length >= 1 && this.adminPwd.length >= 1) {
        ALoginService.checkID(this.adminName, this.adminPwd).then(res => {
          if (res.data.login === 1) {
            localStorage.setItem(
              "MW__AIDMd5",
              JSON.stringify(res.data.list[0])
            );
            this.$emit("changeLoad", "");
            this.userNameError = false;
            this.userPwdError = false;
          } else {
            this.userNameError = true;
            this.userPwdError = true;
          }
        });
      } else {
        if (!this.userNameError) {
          this.userNameError = true;
        }
        if (!this.userPwdError) {
          this.userPwdError = true;
        }
      }
    },
    back() {
      this.$router.push('/');
    }
  },
  created() {
    location.origin === 'http://localhost:8080'? this._src = '//localhost:80/': this._src = '//www.miao-wu.cn/';
  },
};
</script>

<style lang="scss">
.adminLogins {
  margin-top: -170px;
  width: 100%;
  height: 100%;
  overflow-y: hidden;
  .adminLogin {
    width: 100%;
    height: 100%;
    .bg {
      width: 100%;
      height: 100%;
      img {
        width: inherit;
        height: inherit;
      }
    }
    .load {
      // top: 0;
      left: 0;
      right: 0;
      bottom: 180px;
      margin: 0 auto;
      width: 440px;
      height: 340px;
      position: absolute;
      .loadBg {
        top: 0;
        left: 0;
        right: 0;
        height: 100%;
        background: rgba(255, 255, 255, 0.7);
        border-radius: 10px;
        box-sizing: border-box;
        box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
        filter: blur(1px);
        position: absolute;
      }
      .inputList {
        top: 0;
        left: 0;
        right: 0;
        padding: 40px 60px;
        position: absolute;
        > div {
          margin-bottom: 20px;
          &:first-child {
            font-size: 38px;
          }
          &.checkBox {
            text-align: left;
            > div {
              margin-bottom: 2px;
            }
            span {
              padding-left: 5px;
              color: red;
            }
          }
        }
      }
    }
  }
}
</style>
